package com.system_jsp.control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.system_jsp.bean.UserBean;
import com.system_jsp.dao.UserDao;
import com.system_jsp.util.MD5;

/**
 * Servlet implementation class UpdateUser
 */
@WebServlet("/UpdateUser")
public class UpdateUser extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		UserBean ub = new UserBean();
		ub.setUsername(request.getParameter("username"));
		ub.setPasswd(MD5.md5Encode(request.getParameter("passwd")));
		ub.setGender(request.getParameter("gender"));
		ub.setBirth(request.getParameter("birth"));
		ub.setPhone(request.getParameter("phone"));
		ub.setAddress(request.getParameter("address"));

		int result = new UserDao().updateuser(ub);
		System.out.println(result);
		if (result == 1) {
			response.sendRedirect("./UserList");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
